<template>
  <div class="cdlist" @click="gettitl">
    <loading v-if="isLoading"></loading>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">主编推荐</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="bookbox">
        <ul>
          <li v-for="(item,x) in book_list[2]"  v-if="x < 3">
            <router-link :to="`/cs?id=${item.id}`">
              <div class="book-1">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p>{{ item.author }}</p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">新书上线</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="bookbox">
        <ul>
          <li v-for="item in book_list[1]">
            <router-link :to="`/cs?id=${item.id}`">
              <div class="book-1">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p>{{ item.author }}</p>
              </div>
            </router-link>
          </li>
          <li v-for="item in book_list[3]">
            <router-link :to="`/cs?id=${item.id}`">
              <div class="book-1">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p>{{ item.author }}</p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>

    <div class="hed butom">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">经典排行榜</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="bookbox">
        <ul>
          <li v-for="(item, i) in book_list[4]" v-if="i < 3">
            <router-link :to="`/cs?id=${item.id}`">
              <b :class="'rank-' + (i + 1)"></b>
              <div class="book-1">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-tb">
                <h4>{{ item.title }}</h4>
                <p>{{ item.author }}</p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <!-- <div class="butom"></div> -->
  </div>
</template>
<script>
import { recommendFunc, reFunc } from "@/request/index";
import Loading from "@/components/loading/indexlist.vue";
export default {
  data() {
    return {
      book_list: [],
      isLoading: true,
    };
  },
  components: {
    Loading
  },
  methods: {
    async csfe() {
      await recommendFunc().then((res) => {
        // console.log(res.data);
        let { navi } = res.data;
        // console.log(navi);
        reFunc(navi[4].url).then((lis) => {
          // console.log(lis);
          let { list } = lis.data;
          this.url = navi[4].url;
          this.book_list = list.map((item) => {
            return item.list;
          });
          this.book_list.splice(0, 2);
          this.book_list.splice(2, 1);
          this.book_list.splice(5, 1);
          // console.log(this.book_list);
        }).catch(err => {
          console.log("请求失败...");
        });
         this.isLoading = false;
      }).catch(err => {
          console.log("请求失败...");
        });
    },
    gettitl(e) {
      if (e.target.textContent === "更多") {
        this.title = e.target.parentNode.firstChild.textContent;
      }
      let titles= this.title
      let urls = this.url
      this.$router.push(`/modo?list_title=${titles}&url=${urls}`);
    },
  },
  created() {
    this.csfe();
  },
};
</script>
<style lang="scss">
@import url(../../static/css/reset.css);
.butom {
  box-sizing: border-box;
  li {
    position: relative;
    b {
      position: absolute;
      top: -2px;
      left: 7.8px;
      right: 0;
      width: 86%;
      height: 22px;
      background: 0 0 no-repeat;
      background-size: 100% auto;
      z-index: 9;
      &.rank-1 {
        background-image: url(../../static/imgs/icon_01.png);
      }
      &.rank-2 {
        background-image: url(../../static/imgs/icon_02.png);
      }
      &.rank-3 {
        background-image: url(../../static/imgs/icon_03.png);
      }
    }
  }
}
.cdlist {
  margin: auto 5%;
  margin-top: 3px;
  .hed {
    width: 100%;
    h3 {
      height: 28px;
      line-height: 28px;
      margin-bottom: 16px;
      font-weight: bold;
      .gradient {
        float: left;
        display: inline-block;
        font-size: 20px;
        color: #1a1a1a;
      }
      .more {
        float: right;
        padding: 0 17px;
        font-size: 13px;
        font-weight: normal;
        color: #999;
        box-sizing: border-box;
        border: 1px solid #f0f0f0;
        border-radius: 28px;
      }
    }
    .bookbox {
      width: 100%;
      // background: black;
      ul {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        li {
          width: 33.33%;
          [class^="book"] {
            margin: 9px;
            img {
              width: 94px;
              height: 132px;
              border-radius: 5px;
            }
          }
          [class^="text"] {
            color: #333;
            outline: none;
            padding-left: 10%;
            text-align: start;
            h4 {
              font-size: 15px;
              line-height: 19px;
              height: 38px;
              max-height: 38px;
              margin: 10px 0 5px;
              overflow: hidden;
              color: #222;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 2;
              -webkit-box-orient: vertical;
            }
            p {
              color: #888;
              line-height: 15px;
              height: 15px;
              font-size: 12px;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
            }
          }
        }
      }
    }
  }
}
</style>
  